home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1996 May
/
EnigmA AMIGA RUN 07 (1996)(G.R. Edizioni)(IT)[!][issue 1996-05][EARSAN CD VI].iso
/
docs
/
corsoguide
/
format.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-09-03
|
1KB
|
66 lines
#include <exec/types.h>
#include <libraries/dosextens.h>
#include <stdio.h>
void main()
{
register LONG lim,rmp,cnt,grand,i,kk;
char In[100],Out[100],str[100];
struct FileHandle *fIn,*fOut;
printf("Limite - "); gets(In); lim = atoi(In);
printf("File in - "); gets(In);
printf("File out - "); gets(Out);
if ((fIn = (struct FileHandle *)Open(In,MODE_OLDFILE)) == NULL)
{
printf("Errore apertura file input.\n");
exit(1);
}
if ((fOut = (struct FileHandle *)Open(Out,MODE_NEWFILE)) == NULL)
{
printf("Errore apertura file output.\n");
Close(fIn);
exit(1);
}
grand = Seek(fIn,0,OFFSET_END);
grand = Seek(fIn,0,OFFSET_BEGINNING);
cnt = 0;
rmp = 0;
while (grand > 0)
{
cnt = lim-rmp;
if (grand < cnt)
{
Read(fIn,str+rmp,grand);
rmp += grand; grand = 0;
Write(fOut,str,rmp);
}
else
{
Read(fIn,str+rmp,cnt);
rmp += cnt; grand -= cnt;
kk = rmp-1;
for (i=rmp-1; i>=0; i--)
{
if (*(str+i) == ' ' || *(str+i) == '\n')
{
*(str+i) = '\n';
kk = i;
i = -1;
}
}
Write(fOut,str,kk+1);
if (kk+1 < rmp)
CopyMem(str+kk+1,str,rmp-(kk+1));
rmp -= (kk+1);
}
}
Close(fOut);
Close(fIn);
exit(0);
}